package nml.webmail;

 import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.internal.seleniumemulation.KeyEvent;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class eastday_com extends WebMail {

	public void send(String uid, String password, String to, String subject, String content) throws Exception {

		try {
			String url = "http://mail.eastday.com/";
			dr.get(url);

			
			dr.findElement(By.name("uid")).sendKeys(uid);
 			dr.findElement(By.name("password")).sendKeys(password);
 			
 			dr.findElement(By.name("face")).sendKeys("                                 HTML 风格                             "); 			
			

			executeScript("loginForm.submit()");
			
		 
			waitWebElement(By.id("index"));
			dr.switchTo().frame("index");
			waitWebElement(By.id("nav"));
			dr.switchTo().frame("nav");
			
			waitWebElement(By.className("COMPOSE")).click();
			
			dr.switchTo().defaultContent().switchTo().frame("index").switchTo().frame("main");
			
			content=StringUtils.remove(content, '\r');
			content=StringUtils.remove(content, '\n');
			content=StringEscapeUtils.escapeJavaScript(content);
			
			
			
			dr.findElement(By.name("to")).sendKeys(to);
			dr.findElement(By.name("subject")).sendKeys(subject);

			
			
			dr.switchTo().frame("htmleditor");
			dr.findElement(By.id("typeeditor")).click();
			
			dr.switchTo().frame("HtmlEditor");
			String js = " document.body.innerHTML ='" + content + "'   ";
			executeScript(js);
			
			
			dr.switchTo().defaultContent().switchTo().frame("index").switchTo().frame("main");
			dr.findElement(By.id("btnSend")).click();
			
			
			
			 

		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
 			dr.quit();
		}
	}

	public static void main(String[] args) {
		try {
			String uid = "qq1331798654";
			String password = "qq3131798654";
			String to = "o21x@qq.com";
			String subject = "图片频道十分钟告警";
			String content = FileUtils.readFileToString(new File("a.txt"));

			new eastday_com().send(uid, password, to, subject, content);
 		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
